<div class="row">
  <a id="save-btn" href="javascript:void(0)" class="btn btn-primary">保存</a>
  <a id="cancel-btn" href="javascript:void(0)" class="btn btn-danger">取消</a>
</div>
<div class="row">
  <form class="form-horizontal">
    <div class="form-group">
      <label class="control-label col-sm-3">刷新频率(ms):</label>
      <div class="col-sm-9">
        <input type="text" class="form-control" id="interval" style="width:200px;">
      </div>
    </div>
  </form>
</div>
<script type="text/javascript">
$(document).ready(function()
{
	getData();
	
	$('#save-btn').on('click', function() 
	{
		saveData();
 	});
	
	$('#cancel-btn').on('click', function() 
	{
		getData();
 	});
});

function getData()
{
	send('/c', 'event=g', function callbackComplete(jqXHR, textStatus)
	{}, 
	function callbackError(jqXHR, textStatus, errorThrown)
	{
		$('#message-body').text(errorThrown);
		$('#message-dialog').modal('show');
	}, 
	function callbackSuccess(data, textStatus, jqXHR)
	{
		var info = JSON.parse(data);
		
		if(info.code == '00000')
		{
			$('#interval').val(info.conf.runInterval);
		}
		else
		{
			$('#message-body').text(info.message);
			$('#message-dialog').modal('show');
		}
	});
}

function saveData()
{
	var src = '';
	
	src = '{';
	src += '\"runInterval\":\"' + $('#interval').val() + '\"';
	src += '}';
	
	send('/c', 'event=s&src=' + src, function callbackComplete(jqXHR, textStatus)
	{}, 
	function callbackError(jqXHR, textStatus, errorThrown)
	{
		$('#message-body').text(errorThrown);
		$('#message-dialog').modal('show');
	}, 
	function callbackSuccess(data, textStatus, jqXHR)
	{
		var info = JSON.parse(data);
		
		if(info.code == '00000')
		{
			$('#message-body').text('保存完成');
			$('#message-dialog').modal('show');
			
			$('#interval').val(info.conf.runInterval);
		}
		else
		{
			$('#message-body').text(info.message);
			$('#message-dialog').modal('show');
		}
	});
}
</script>